<template>
  <div v-for="(comment, index) in comments" :key="index" class="comment-item">
    <img :src="GetHeadImage(comment.head)" class="head" />
    <div class="comment-content">
      <div class="user-info">
        <span class="username">{{ comment.username }}</span>
        <span class="label">{{ comment.label }}</span>
      </div>
      <div class="comment-details">
        <span>{{ comment.detailMessage }}</span>
        <span class="timestamp" style="margin-left: 8px;">{{ comment.timestamp }}</span>
      </div>
      <div v-if="comment.isReplying" class="reply-box">
        <input
          type="text"
          v-model="comment.replyMessage"
          :placeholder="'回复 ' + comment.username"
        />
        <button @click="showEmojis(comment)" style="border: 0;">
          <svg class="icon" aria-hidden="true">
            <use href="#icon-xxsxtfbq"></use> 
          </svg>
         
        </button>
        <transition name="slide" v-if="comment.replyMessage">
          <button class="send-button" @click="sendReply(comment)">发送</button>
        </transition>
        <button @click="cancelReply(comment)">取消</button>
      </div>
      <div class="action-buttons" v-else>
        <button @click="() => reply(comment)" class="reply">
                    <svg class="icon" aria-hidden="true">
            <use href="#icon-pinglun"></use> 
          </svg>
          
          回复</button>
        <button @click="() => like(comment)" class="aixin_1">
          {{ comment.like === 1 ? "❤️" : "🤍" }}
        </button>
      </div>
    </div>
    <img src="@/assets/img/img02.jpg" class="zoom-icon" />
  </div>
</template>

<script setup>
import { defineProps, ref } from "vue";
import "@/assets/download/iconfont.js";
const props = defineProps({
  comments: {
    type: Array,
    required: true,
  },
});
const comments = ref(props.comments);
const reply = (comment) => {
  comment.isReplying = true;
  comment.replyMessage = "";
};

const cancelReply = (comment) => {
  comment.isReplying = false;
};

const sendReply = (comment) => {
  console.log("发送回复给", comment.username, ":", comment.replyMessage);
  comment.isReplying = false;
};

const showEmojis = (comment) => {
  // 显示表情选择窗口的逻辑
};

const like = (comment) => {
  comment.like = comment.like === 1 ? 0 : 1;
};

const GetHeadImage = (imgsrc) => new URL(imgsrc, import.meta.url).href;
</script>

<style scoped>
.icon {
  width: 20px;
  height: 20px;
  vertical-align: -0.15em;
  fill: currentColor;
  overflow: hidden;
}
.comment-item {
  margin-left: 70px;
  display: flex;
  max-height: 100vh;
  align-items: center;
  border-bottom: 1px solid #eee;
  padding: 24px 0 0 0;
}

.head {
  position: relative;
  top: -32px;
  margin-right: 24px;
  border-radius: 50%;
  width: 48px;
  height: 48px;
}
.comment-content {
  flex-grow: 1;
  padding: 0 0 24px;
}
.user-info {
  display: flex;
  align-items: center;
  padding: 0 0 4px;
}
.label {
  float: left;
  color: #33333399;
  background-color: #00000008;
  font-size: 12px;
  padding: 2px 5px;
  border-radius: 10px;
}
.comment-details{
  padding: 0 0 8px;
}
.comment-details span{
  font-size: 14px;
  color: #33333399;

}
.action-buttons {
  display: flex;
  gap: 15px;
}
.reply{
  height: 40px;
  width: 88px;
  font-size: 16px;
  border-radius: 20px;
  border: 0.1px solid rgba(0, 0, 0, 0.1);
  background-color: #fff;
}
.reply-box {
  display: flex;
  align-items: center;
  width: 100%;
  position: relative;
}
.aixin_1{
  width: 34px;
  height: 34px;
  border-radius: 50%;
   border: 0.1px solid rgba(0, 0, 0, 0.1);
   background-color: #fff;
}
.reply-box input {
  width: inherit;
  height: 40px;
  border-radius: 20px;
  padding: 0 10px;
  border: 0.1px solid rgba(197, 194, 194, 0.1);
  background-color: #00000008;
}
.reply-box button {
  width: 90px;
  height: 40px;
  margin-left: 8px;
  border-radius: 44px;
  font-size: 16px;
  border: 0.1px solid rgba(0, 0, 0, 0.1);
  background-color: #fff;
  transition: background-color 3.76s ease;
  margin-left: 5px;
  cursor: pointer;
}

.comment-item .send-button {
  background-color: #ff2442;
  color: #ffffff;
}
.slide-enter-active,
.slide-leave-active {
  transition: transform 2s ease;
}
.slide-enter-from {
  transform: translateX(100%);
}
.slide-leave-to {
  transform: translateX(-20px); /* 向右滑动 */
}

.reply-box button:hover {
  background-color: #adaaaa; /* 悬停时的背景颜色 */
}

</style>
